<?php
  require_once 'etc/config.php';
  $current = (int)date('Hi'); 
  if($current < 920 || ($current > 1130 && $current<1300) || $current > 1500){
    exit;
  }
  require_once 'stock.class.php';
  $stock = new Stock();
  $monitors = $stock->getMonitors();
  foreach ($monitors as $row) {
    $data = $stock->getCurrent($row['code']);
    $stock->update($row['code'], $data);
    if ($row['status'] && $row['profit_price'] && $data['current'] >= $row['profit_price']) {
      $content = "Notice: $row[code] current is $data[current] rise your profit price: $row[profit_price]";
      $stock->sendNotice($content);
      //$stock->disableAlarm($row['id']);
      $stock->updateAlarm($row['id'], 'up');
    }
    if ($row['status'] && $row['loss_price'] && $data['current'] < $row['loss_price']) {
      $content = "Warning: $row[code] current is $data[current] fall your loss price: $row[loss_price]";
      $stock->sendNotice($content);
      $stock->updateAlarm($row['id'], 'down');
      //$stock->disableAlarm($row['id']);
    }
  }
